package com.dianping.cat.alarm.rule.transform;

import com.dianping.cat.alarm.rule.entity.Condition;
import com.dianping.cat.alarm.rule.entity.Config;
import com.dianping.cat.alarm.rule.entity.MetricItem;
import com.dianping.cat.alarm.rule.entity.MonitorRules;
import com.dianping.cat.alarm.rule.entity.Rule;
import com.dianping.cat.alarm.rule.entity.SubCondition;
import java.util.Map;
import org.xml.sax.Attributes;















public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Condition buildCondition(Attributes attributes) {
    String minute = attributes.getValue("minute");
    String title = attributes.getValue("title");
/*  33 */     String alertType = attributes.getValue("alertType");
/*  34 */     Condition condition = new Condition();

    if (minute != null) {
/*  37 */       condition.setMinute((Integer)convert(Integer.class, minute, null));
    }

/*  40 */     if (title != null) {
/*  41 */       condition.setTitle(title);
    }

/*  44 */     if (alertType != null) {
/*  45 */       condition.setAlertType(alertType);
    }

/*  48 */     return condition;
  }


  public Config buildConfig(Attributes attributes) {
/*  53 */     String starttime = attributes.getValue("starttime");
/*  54 */     String endtime = attributes.getValue("endtime");
/*  55 */     Config config = new Config();

/*  57 */     if (starttime != null) {
/*  58 */       config.setStarttime(starttime);
    }

/*  61 */     if (endtime != null) {
/*  62 */       config.setEndtime(endtime);
    }

/*  65 */     return config;
  }


  public MetricItem buildMetricItem(Attributes attributes) {
/*  70 */     String monitorCount = attributes.getValue("monitorCount");
/*  71 */     String monitorSum = attributes.getValue("monitorSum");
/*  72 */     String monitorAvg = attributes.getValue("monitorAvg");
/*  73 */     String metricItemText = attributes.getValue("metricItemText");
/*  74 */     String productText = attributes.getValue("productText");
/*  75 */     MetricItem metricItem = new MetricItem();

/*  77 */     if (monitorCount != null) {
      metricItem.setMonitorCount((Boolean)convert(Boolean.class, monitorCount, null));
    }

/*  81 */     if (monitorSum != null) {
/*  82 */       metricItem.setMonitorSum((Boolean)convert(Boolean.class, monitorSum, null));
    }

/*  85 */     if (monitorAvg != null) {
/*  86 */       metricItem.setMonitorAvg((Boolean)convert(Boolean.class, monitorAvg, null));
    }

/*  89 */     if (metricItemText != null) {
/*  90 */       metricItem.setMetricItemText(metricItemText);
    }

/*  93 */     if (productText != null) {
/*  94 */       metricItem.setProductText(productText);
    }

/*  97 */     return metricItem;
  }



/* 102 */   public MonitorRules buildMonitorRules(Attributes attributes) { return new MonitorRules(); }





  public Rule buildRule(Attributes attributes) {
/* 109 */     String id = attributes.getValue("id");
/* 110 */     Rule rule = new Rule(id);

/* 112 */     Map<String, String> dynamicAttributes = rule.getDynamicAttributes();
/* 113 */     int _length = (attributes == null) ? 0 : attributes.getLength();

/* 115 */     for (int i = 0; i < _length; i++) {
/* 116 */       String _name = attributes.getQName(i);
/* 117 */       String _value = attributes.getValue(i);

/* 119 */       dynamicAttributes.put(_name, _value);
    }

/* 122 */     dynamicAttributes.remove("id");

/* 124 */     return rule;
  }


  public SubCondition buildSubCondition(Attributes attributes) {
/* 129 */     String type = attributes.getValue("type");
/* 130 */     String text = attributes.getValue("text");
/* 131 */     SubCondition subCondition = new SubCondition();

/* 133 */     if (type != null) {
/* 134 */       subCondition.setType(type);
    }

/* 137 */     if (text != null) {
/* 138 */       subCondition.setText(text);
    }

/* 141 */     return subCondition;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 146 */     if (value == null || value.length() == 0) {
/* 147 */       return defaultValue;
    }

/* 150 */     if (type == Boolean.class || type == boolean.class)
/* 151 */       return (T)Boolean.valueOf(value); 
/* 152 */     if (type == Integer.class || type == int.class)
/* 153 */       return (T)Integer.valueOf(value); 
/* 154 */     if (type == Long.class || type == long.class)
/* 155 */       return (T)Long.valueOf(value); 
/* 156 */     if (type == Short.class || type == short.class)
/* 157 */       return (T)Short.valueOf(value); 
/* 158 */     if (type == Float.class || type == float.class)
/* 159 */       return (T)Float.valueOf(value); 
/* 160 */     if (type == Double.class || type == double.class)
/* 161 */       return (T)Double.valueOf(value); 
/* 162 */     if (type == Byte.class || type == byte.class)
/* 163 */       return (T)Byte.valueOf(value); 
/* 164 */     if (type == Character.class || type == char.class) {
/* 165 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 167 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-alarm-3.0.0.jar!/com/dianping/cat/alarm/rule/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */